package com.xinqi.modules.prepare.prepare.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.xinqi.common.base.annotations.Describe;
import com.xinqi.common.base.enums.BaseEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 备课区题型
 * <p>
 * 备课区题型，1:判断题；2:单选题；3:多选题；4:不定项题；5: 填空题；6:简答题；
 * </p>
 *
 * @author linkai
 * @date 2023/03/19
 */
@Describe("备课区题型")
public enum PrepareQuestionTypeEnum implements BaseEnum {

    ANSWER_JUDGE("1", "判断题"),
    ANSWER_RADIO("2", "单选题"),
    ANSWER_MULTIPLE("3", "多选题"),
    ANSWER_INDEFINITE("4", "不定项选择题"),
    ANSWER_CLOZE("5", "填空题"),
    ANSWER_SHORT("6", "简答题"),
    ;

    @Getter(onMethod_ = {@JsonValue})
    private final String code;

    @Getter
    private final String describe;

    PrepareQuestionTypeEnum(String code, String describe) {
        this.code = code;
        this.describe = describe;
    }

    @JsonCreator
    public static PrepareQuestionTypeEnum of(String code) {
        return BaseEnum.of(PrepareQuestionTypeEnum.class, code);
    }

    public static String getCode(String text) {
        for (PrepareQuestionTypeEnum typeEnum : PrepareQuestionTypeEnum.values()) {
            if (text.contains(typeEnum.getDescribe())) {
                return typeEnum.getCode();
            }
        }
        return "0";
    }

    public static String getDescribe(String code) {
        for (PrepareQuestionTypeEnum typeEnum : PrepareQuestionTypeEnum.values()) {
            if (Objects.equals(typeEnum.getCode(), code)) {
                return typeEnum.getDescribe();
            }
        }
        return "";
    }

}
